﻿using Shop.RemoteModel.Goods.Model;
using Shop.RemoteModel.SpuGoods.Model;
using Shop.StoreGatewayModular.Interface;
using Shop.StoreGatewayModular.Linq;
using WeDonekRpc.ApiGateway.Attr;
using WeDonekRpc.Client;
using WeDonekRpc.Helper.Validate;
using WeDonekRpc.HttpApiGateway;
using WeDonekRpc.HttpApiGateway.Model;

namespace Shop.StoreGatewayModular.Api
{
    [ApiRouteName("/shop/goods/{name}")]
    internal class GoodsApi : ApiController
    {
        private readonly IGoodsService _Service;

        public GoodsApi ( IGoodsService service )
        {
            this._Service = service;
        }
        public SpuDatum[] GetTops ( TopGetArg arg )
        {
            return _Service.GetTops ( arg );
        }
        public GoodsDto[] Gets ( [NullValidate("shop.goods.id.null")] long[] ids )
        {
            return this._Service.Gets(ids);
        }
        public GoodsStock[] GetStocks ( [NumValidate("shop.goods.id.error", 1)] long goodsId )
        {
            return this._Service.GetStocks(goodsId);
        }
        public GoodsDetailed GetDetailed ( [NumValidate("shop.goods.id.error", 1)] long id )
        {
            return this._Service.GetDetailed(id);
        }
        public long Add ( GoodsSet datum )
        {
            return this._Service.Add(datum);
        }

        public void Delete ( [NumValidate("shop.goods.id.error", 1)] long id )
        {
            this._Service.Delete(id);
        }

        public GoodsDatum Get ( [NumValidate("shop.goods.id.error", 1)] long id )
        {
            return this._Service.Get(id);
        }

        public void Offshelf ( [NumValidate("shop.goods.id.error", 1)] long id )
        {
            this._Service.Offshelf(id);
        }

        public void Public ( LongParam<Dictionary<long, int>> param )
        {
            long userId = base.UserState.ToUserId();
            this._Service.Public(param.Id, userId, param.Value);
        }

        public PagingResult<GoodsDto> Query ( PagingParam<GoodsQueryParam> query )
        {
            return this._Service.Query(query);
        }

        public bool Set ( LongParam<GoodsSet> param )
        {
            return this._Service.Set(param.Id, param.Value);
        }
    }
}
